import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:material_collection_app/utils/dio_utils.dart';
import 'package:material_collection_app/utils/event_bus_util.dart';
import 'package:material_collection_app/widget/common/refresh.dart';
import 'package:material_collection_app/widget/common/round_checkbox.dart';
import 'package:material_collection_app/widget/common/top_bar.dart';
import 'package:material_collection_app/widget/out/scan_result.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import '../utils/utils.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

class PartOutLibraryPage extends StatefulWidget {
  final Map arguments;

  PartOutLibraryPage({Key key, this.arguments}) : super(key: key);

  @override
  State<StatefulWidget> createState() => MyState();
}

class MyState extends State<PartOutLibraryPage> {
  RefreshController _refreshController =
      RefreshController(initialRefresh: false);
  List list = [];
  bool loadSuccess = false;
  List selected = [];
  List confirmList = [];
  bool isSelectedAll = false;
  String baseApi = '';
  var eventBus = new EventBus();

  @override
  void initState() {
    super.initState();
    EasyLoading.instance..userInteractions = false;
    String model = widget.arguments['item']['model'];

    if (model == 'scrap') {
      setState(() {
        baseApi = 'scrapGoodsOut/';
      });
    } else if (model == 'allocate') {
      setState(() {
        baseApi = 'allocateGoodsOut/';
      });
    } else {
      setState(() {
        baseApi = 'goodsOut/';
      });
    }

    _loadData();

    eventBus.on("part_scan_result", (parmas) {
      showScanResult(list, parmas['rfidList']);
    });
  }

  // 加载数据
  void _loadData() async {
    var id = widget.arguments['item']['out_id'];
    loadSuccess = false;

    DioUtils.request("${baseApi}detail",
        context: context,
        method: "POST",
        params: {
          'id': id,
        }, onSuccess: (res) {
      if (res['code'] == 1) {
        if (mounted) {
          setState(() {
            list = res["data"]["goods"];
            loadSuccess = true;
          });
          for (int i = 0; i < list.length; i++) {
            var item = list[i];
            setState(() {
              selected.add({'selected': false, 'out_id': item['out_id']});
            });
            // 子物资
          }
        }
      } else {
        Utils.showText(text: res['msg']);
      }
    }, onError: (error) {});
  }

  void _onRefresh() async {
    _refreshController.loadComplete();
    _loadData();
    await Future.delayed(Duration(milliseconds: 600));
    _refreshController.refreshCompleted();
  }

  void _onLoading() async {
    await Future.delayed(Duration(milliseconds: 10));
    _refreshController.loadNoData();
  }

  Future<void> showScanResult(goods, rfidList) async {
    showDialog(
        context: context,
        builder: (context) {
          return Dialog(
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(Radius.circular(12.w))),
              insetPadding: EdgeInsets.all(0),
              child: ScanResult(
                  goods: goods, rfidList: rfidList, scanConfirm: _scanConfirm));
        });
  }

  _scanConfirm(index) {
    _confirmInfo(index);
  }

  Widget _buildButton(title, color, type) {
    return Container(
      height: 60.w,
      margin: EdgeInsets.only(right: 20.w),
      child: SizedBox(
        child: ElevatedButton(
          onPressed: () {
            if (type == 1) {
              _confirmInfos();
            } else if (type == 2) {
              Navigator.pushNamed(context, '/scan_result',
                  arguments: {'page': 'part_out', 'back': 1});
            }
          },
          child: Text(
            title,
            style: TextStyle(
                color: Utils.hexToColor(color), fontSize: 14, height: 1),
          ),
          style: ElevatedButton.styleFrom(
            backgroundColor: Utils.hexToColor('#F5F3F3'),
            padding: EdgeInsets.fromLTRB(33.w, 0, 33.w, 0),
            shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(60.w))),
          ),
        ),
      ),
    );
  }

  // 批量确认信息
  _confirmInfos() {
    int selectedLength = 0;
    int confirmListLen = confirmList.length;

    for (int i = 0; i < selected.length; i++) {
      var item = selected[i];
      if (item['selected']) {
        selectedLength++;
      }
    }
    if (selectedLength == 0) {
      Utils.showText(text: '请选择物资');
      return;
    }
    if (confirmListLen >= selected.length) {
      for (int i = 0; i < selected.length; i++) {
        var item = selected[i];
        if (item['selected']) {
          setState(() {
            confirmList[i] = true;
          });
        }
      }
    } else {
      confirmList = [];
      for (int i = 0; i < selected.length; i++) {
        var item = selected[i];
        if (item['selected']) {
          setState(() {
            confirmList.add(true);
          });
        }
      }
    }
  }

  // 完成出库
  _out() {
    int confirmLength = 0;

    for (int i = 0; i < confirmList.length; i++) {
      var item = confirmList[i];
      if (item) {
        confirmLength++;
      }
    }

    if (confirmLength == selected.length) {
      int id = widget.arguments['item']['out_id'];
      EasyLoading.show(status: '提交数据中,请稍后....');
      DioUtils.request("${baseApi}doAction",
          context: context,
          method: "POST",
          params: {'out_id': id, 'status': 'out', 'business_group_remark': ''},
          onSuccess: (res) {
        if (res['code'] == 1) {
          EasyLoading.dismiss();
          this.showSubmitDialog();
          eventBus.emit(
              'out_return', {'index': widget.arguments['item']['itemIndex']});
          Navigator.of(context).pop();
          Navigator.of(context).pop("refresh");
        } else {
          Utils.showText(text: res['msg']);
          EasyLoading.dismiss();
        }
      }, onError: (error) {
        EasyLoading.dismiss();
      });
    } else {
      Utils.showText(text: '请确认完所有物资信息');
    }
  }

  // 退回
  _back() {
    int id = widget.arguments['item']['out_id'];
    List goods = [];

    for (int i = 0; i < list.length; i++) {
      var item = list[i];
      goods.add({'lists_id': item['lists_id'], 'check_status': 2});
    }

    DioUtils.request("${baseApi}doAction",
        context: context,
        method: "POST",
        params: {'out_id': id, 'status': 'back', 'goods': goods},
        onSuccess: (res) {
      Utils.showText(text: res['msg']);
      if (res['code'] == 1) {
        eventBus.emit(
            'out_return', {'index': widget.arguments['item']['itemIndex']});
        Navigator.of(context).pop();
      }
    }, onError: (error) {});
  }

  // 确认信息
  _confirmInfo(int index) {
    if (index < list.length) {
      setState(() {
        confirmList[index] = true;
      });
    }
  }

  // 确认信息按钮
  Widget _buildConfirmButton(
    Map item,
    int index,
  ) {
    var list = item['goods_son_list'];
    if (confirmList[index] == false) {
      return Positioned(
          right: 0,
          top: 30.w,
          child: Row(
            children: [
              Container(
                margin: EdgeInsets.only(right: 8.w),

                /*
                child: SizedBox(
                  width: 120.w,
                  height: 66.w,
                  child: ElevatedButton(
                      padding: EdgeInsets.symmetric(horizontal: 0),
                      color: Utils.hexToColor('#297CFF'),
                      onPressed: () {
                        // _confirmInfo(index);
                        // this.showMaterialInfoDialog();
                        //  print(list);
                        _toPage(list);
                      },
                      child: Text('子物资',
                          style: TextStyle(
                              color: Colors.white, fontSize: 14, height: 1)),
                      shape: RoundedRectangleBorder(
                          borderRadius:
                              BorderRadius.all(Radius.circular(8.w)))),
                ),*/
              ),
              SizedBox(
                width: 160.w,
                height: 66.w,
                child: ElevatedButton(
                  style: ElevatedButton.styleFrom(
                      padding: EdgeInsets.symmetric(horizontal: 0),
                      backgroundColor: Utils.hexToColor('#297CFF'),
                      shape: RoundedRectangleBorder(
                          borderRadius:
                              BorderRadius.all(Radius.circular(8.w)))),
                  onPressed: () {
                    _confirmInfo(index);
                    // this.showMaterialInfoDialog();
                  },
                  child: Text('确认信息',
                      style: TextStyle(
                          color: Colors.white, fontSize: 14, height: 1)),
                ),
              ),
            ],
          ));
    } else {
      return Positioned(
          right: 0,
          top: 30.w,
          child: Row(
            children: [
              Container(
                margin: EdgeInsets.only(right: 8.w),
                child: SizedBox(
                  width: 120.w,
                  height: 66.w,
                  child: ElevatedButton(
                    style: ElevatedButton.styleFrom(
                        padding: EdgeInsets.symmetric(horizontal: 0),
                        backgroundColor: Utils.hexToColor('#297CFF'),
                        shape: RoundedRectangleBorder(
                            borderRadius:
                                BorderRadius.all(Radius.circular(8.w)))),
                    onPressed: () {
                      // _confirmInfo(index);
                      // this.showMaterialInfoDialog();
                      _toPage(list);
                    },
                    child: Text('子物资',
                        style: TextStyle(
                            color: Colors.white, fontSize: 14, height: 1)),
                  ),
                ),
              ),
            ],
          ));
      // return Container();
    }
  }

  _toPage(list) {
    if (list.length <= 0) {
      Utils.showText(text: '没有子物资');
      return;
    }

    Navigator.pushNamed(context, '/son_out_material',
        arguments: {'list': list});
  }

  Widget _buildPageTwo() {
    return Container(
        color: Utils.hexToColor('#F5F6FA'),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            Expanded(
                flex: 1,
                child: Refresh(
                    refreshController: _refreshController,
                    onRefresh: _onRefresh,
                    onLoading: _onLoading,
                    child: ListView.builder(
                        itemCount: list.length,
                        padding: EdgeInsets.only(bottom: 60),
                        itemBuilder: (BuildContext context, int index) {
                          var item = list[index];
                          // selected.add({'selected': false, 'out_id': item['out_id']});
                          confirmList.add(false);
                          String status =
                              confirmList[index] == false ? '未确认' : '已确认';

                          return InkWell(
                            onTap: () {},
                            child: Container(
                              width: 00.w,
                              height: 315.w,
                              margin: EdgeInsets.fromLTRB(25.w, 20.w, 25.w, 0),
                              padding: EdgeInsets.fromLTRB(24.w, 0, 24.w, 0.w),
                              decoration: BoxDecoration(
                                color: confirmList[index]
                                    ? Utils.hexToColor('#E9F2F5')
                                    : Colors.white,
                                borderRadius: BorderRadius.circular(20.w),
                              ),
                              child: Row(
                                children: <Widget>[
                                  Stack(
                                    children: <Widget>[
                                      Container(
                                          height: 45,
                                          // margin: EdgeInsets.only(top: 14, left: 5),
                                          child: Center(
                                            child: Text((index + 1).toString()),
                                          )),
                                      RoundCheckBox(
                                        select: selected[index]['selected'],
                                        onChanged: () {
                                          setState(() {
                                            selected[index]['selected'] =
                                                !selected[index]['selected'];
                                          });
                                        },
                                      ),
                                    ],
                                  ),
                                  Container(
                                    width: 580.w,
                                    margin: EdgeInsets.only(left: 20.w),
                                    child: Column(
                                      children: <Widget>[
                                        Container(
                                          height: 90.w,
                                          decoration: BoxDecoration(
                                              border: Border(
                                                  bottom: BorderSide(
                                                      color: Utils.hexToColor(
                                                          '#EEEEEE')))),
                                          child: Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.spaceBetween,
                                            children: <Widget>[
                                              Container(
                                                width: 450.w,
                                                child: Row(
                                                  children: <Widget>[
                                                    Text('RFID号：'),
                                                    Expanded(
                                                      child: Text(
                                                          item['rfid_code'],
                                                          maxLines: 1,
                                                          overflow: TextOverflow
                                                              .ellipsis),
                                                    )
                                                  ],
                                                ),
                                              ),
                                              Text(status,
                                                  style: TextStyle(
                                                      color: Utils.hexToColor(
                                                          '#F65654'),
                                                      fontSize: 14)),
                                            ],
                                          ),
                                        ),
                                        Container(
                                            alignment: Alignment.topLeft,
                                            padding: EdgeInsets.fromLTRB(
                                                0, 0.w, 0, 34.w),
                                            child: Row(
                                              mainAxisAlignment:
                                                  MainAxisAlignment
                                                      .spaceBetween,
                                              children: <Widget>[
                                                Stack(
                                                  children: <Widget>[
                                                    Column(
                                                      crossAxisAlignment:
                                                          CrossAxisAlignment
                                                              .start, // 左对齐
                                                      children: <Widget>[
                                                        Container(
                                                          margin:
                                                              EdgeInsets.only(
                                                                  top: 34.w),
                                                          child: Text(
                                                              item[
                                                                  'goods_name'],
                                                              style: TextStyle(
                                                                  color: Color(
                                                                      0xFF333333),
                                                                  fontSize: 15,
                                                                  fontWeight:
                                                                      FontWeight
                                                                          .bold,
                                                                  height: 1)),
                                                        ),
                                                        Container(
                                                          margin:
                                                              EdgeInsets.only(
                                                                  top: 23.w),
                                                          child: Text(
                                                              '物资分类：' +
                                                                  item[
                                                                      'type_name'],
                                                              style: TextStyle(
                                                                  color: Color(
                                                                      0xFF666666),
                                                                  fontSize: 12,
                                                                  height: 1)),
                                                        ),
                                                        Row(
                                                          children: <Widget>[
                                                            Container(
                                                              width: 250.w,
                                                              margin: EdgeInsets
                                                                  .only(
                                                                      top:
                                                                          13.w),
                                                              child: Text(
                                                                  '物资数量：' +
                                                                      item['num']
                                                                          .toString(),
                                                                  maxLines: 1,
                                                                  overflow:
                                                                      TextOverflow
                                                                          .ellipsis,
                                                                  style: TextStyle(
                                                                      color: Color(
                                                                          0xFF666666),
                                                                      fontSize:
                                                                          12,
                                                                      height:
                                                                          1)),
                                                            ),
                                                            Container(
                                                              width: 300.w,
                                                              margin: EdgeInsets
                                                                  .only(
                                                                      left:
                                                                          30.w,
                                                                      top:
                                                                          13.w),
                                                              child: Text(
                                                                  '所属仓库：' +
                                                                      item[
                                                                          'store_name'],
                                                                  maxLines: 1,
                                                                  overflow:
                                                                      TextOverflow
                                                                          .ellipsis,
                                                                  style: TextStyle(
                                                                      color: Color(
                                                                          0xFF666666),
                                                                      fontSize:
                                                                          12,
                                                                      height:
                                                                          1)),
                                                            ),
                                                          ],
                                                        ),
                                                        Row(
                                                          children: <Widget>[
                                                            Container(
                                                              width: 250.w,
                                                              margin: EdgeInsets
                                                                  .only(
                                                                      top:
                                                                          13.w),
                                                              child: Text(
                                                                  '推荐库区：' +
                                                                      item[
                                                                          'store_library_name'],
                                                                  maxLines: 1,
                                                                  overflow:
                                                                      TextOverflow
                                                                          .ellipsis,
                                                                  style: TextStyle(
                                                                      color: Color(
                                                                          0xFF666666),
                                                                      fontSize:
                                                                          12,
                                                                      height:
                                                                          1)),
                                                            ),
                                                            Container(
                                                              width: 300.w,
                                                              margin: EdgeInsets
                                                                  .only(
                                                                      left:
                                                                          30.w,
                                                                      top:
                                                                          13.w),
                                                              child: Text(
                                                                  '所属库位：' +
                                                                      item[
                                                                          'store_detail_code'],
                                                                  maxLines: 1,
                                                                  overflow:
                                                                      TextOverflow
                                                                          .ellipsis,
                                                                  style: TextStyle(
                                                                      color: Color(
                                                                          0xFF666666),
                                                                      fontSize:
                                                                          12,
                                                                      height:
                                                                          1)),
                                                            ),
                                                          ],
                                                        )
                                                      ],
                                                    ),
                                                    _buildConfirmButton(
                                                        item, index)
                                                  ],
                                                )
                                              ],
                                            ))
                                      ],
                                    ),
                                  )
                                ],
                              ),
                            ),
                          );
                        })))
          ],
        ));
  }

  Widget _buildInput(title) {
    return Container(
      margin: EdgeInsets.only(bottom: 20.h),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Container(
            width: 160.w,
            alignment: Alignment.centerRight,
            child: Text(
              title + '：',
              // textAlign: TextAlign.end,
              style:
                  TextStyle(color: Utils.hexToColor('#999999'), fontSize: 14),
            ),
          ),
          Container(
            width: 460.w,
            height: 70.h,
            child: TextField(
              style: TextStyle(fontSize: 14, color: Colors.black), //输入文本的样式
              decoration: InputDecoration(
                hintText: "请输入" + title,
                hintStyle: TextStyle(color: Color(0xFFC8C8D9), fontSize: 14),
                contentPadding: EdgeInsets.fromLTRB(21.w, 0, 21.w, 0),
                fillColor: Colors.white,
                filled: true,
                enabledBorder: OutlineInputBorder(
                  borderRadius: BorderRadius.all(
                    Radius.circular(8.w),
                  ),
                  borderSide: BorderSide(
                    color: Utils.hexToColor('#D4D4D4'),
                    width: 1,
                  ),
                ),
                focusedBorder: OutlineInputBorder(
                  borderSide: BorderSide(
                    color: Utils.hexToColor('#D4D4D4'),
                    width: 1,
                  ),
                  borderRadius: BorderRadius.all(
                    Radius.circular(8.w),
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildImageBox() {
    return Container(
      margin: EdgeInsets.only(bottom: 20.h),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            width: 160.w,
            margin: EdgeInsets.only(top: 20.w),
            alignment: Alignment.centerRight,
            child: Text(
              '图片：',
              // textAlign: TextAlign.end,
              style:
                  TextStyle(color: Utils.hexToColor('#999999'), fontSize: 14),
            ),
          ),
          Container(
              width: 460.w,
              child: Wrap(
                spacing: 25.w,
                runSpacing: 25.w,
                children: <Widget>[
                  Container(
                    // margin: EdgeInsets.only(right: 31.w, bottom: 31.w),
                    child: Stack(
                      children: <Widget>[
                        ClipRRect(
                          borderRadius: BorderRadius.all(Radius.circular(8.w)),
                          child: Image.asset('assets/avatar.png',
                              width: 136.w, height: 136.w),
                        ),
                        Positioned(
                          top: 96.w,
                          child: Container(
                            width: 136.w,
                            height: 40.w,
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                              color: Color.fromRGBO(0, 0, 0, 0.4),
                              borderRadius: BorderRadius.vertical(
                                  bottom: Radius.elliptical(8.w, 8.w)),
                            ),
                            child: Text('删除图片',
                                style: TextStyle(
                                    color: Colors.white, fontSize: 10)),
                          ),
                        )
                      ],
                    ),
                  ),
                  Container(
                      child: InkWell(
                    onTap: () {},
                    child: Image.asset('assets/add_img.png',
                        width: 136.w, height: 136.w),
                  )),
                ],
              )),
        ],
      ),
    );
  }

  Future<void> showMaterialInfoDialog() async {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return Dialog(
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(Radius.circular(12.w))),
              insetPadding: EdgeInsets.all(0),
              child: Container(
                  width: 700.w,
                  height: 1161.w,
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.all(Radius.circular(100))),
                  child: Column(
                    children: <Widget>[
                      _buildDialogHead('物资信息'),
                      Expanded(
                        flex: 1,
                        child: SingleChildScrollView(
                          child: Container(
                            padding: EdgeInsets.all(40.w),
                            child: Column(
                              children: <Widget>[
                                _buildInput('物资编号'),
                                _buildInput('物资名称'),
                                _buildInput('物资类型'),
                                _buildInput('物资数量'),
                                _buildInput('规格/型号'),
                                _buildInput('单位'),
                                _buildInput('备注'),
                                _buildImageBox()
                              ],
                            ),
                          ),
                        ),
                      ),
                      Container(
                        height: 120.w,
                        // color: Utils.hexToColor('#FFFFFF'),
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                            border: Border(
                                top: BorderSide(
                                    width: 1,
                                    color: Utils.hexToColor('#F2F2F2')))),
                        child: SizedBox(
                          width: 620.w,
                          height: 76.w,
                          child: ElevatedButton(
                            onPressed: () {
                              Navigator.of(context).pop();
                            },
                            child: Text(
                              '确认信息',
                              style: TextStyle(color: Colors.white),
                            ),
                            style: ElevatedButton.styleFrom(
                              backgroundColor: Color(0xFF297CFF),
                              shape: RoundedRectangleBorder(
                                  borderRadius:
                                      BorderRadius.all(Radius.circular(60.w))),
                            ),
                          ),
                        ),
                      ),
                    ],
                  )));
        });
  }

  Widget _buildDialogHead(title) {
    return Container(
      height: 80.w,
      decoration: BoxDecoration(
          color: Utils.hexToColor('#F7F7F7'),
          borderRadius: BorderRadius.only(
              topLeft: Radius.circular(12.w), topRight: Radius.circular(12.w))),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Container(
            margin: EdgeInsets.only(left: 31.w),
            child: Text(title,
                style: TextStyle(
                    color: Utils.hexToColor('#333333'),
                    fontSize: 16,
                    fontWeight: FontWeight.bold)),
          ),
          GestureDetector(
            onTap: () {
              Navigator.of(context).pop();
            },
            child: Container(
              padding: EdgeInsets.fromLTRB(30.w, 24.w, 30.w, 24.w),
              alignment: Alignment.topRight,
              child: Image.asset(
                'assets/dialog_close.png',
                width: 36.w,
              ),
            ),
          )
        ],
      ),
    );
  }

  Future<void> showScanBindRfidDialog() async {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return Dialog(
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(Radius.circular(12.w))),
              insetPadding: EdgeInsets.all(0),
              child: Container(
                  width: 660.w,
                  height: 960.w,
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.all(Radius.circular(100))),
                  child: Column(
                    children: <Widget>[
                      _buildDialogHead('绑定RFID'),
                      Expanded(
                          flex: 1,
                          child: SingleChildScrollView(
                            child: Container(
                              padding: EdgeInsets.all(40.w),
                              child: Column(
                                children: <Widget>[
                                  Row(
                                    mainAxisAlignment:
                                        MainAxisAlignment.spaceBetween,
                                    children: <Widget>[
                                      Container(
                                        alignment: Alignment.centerRight,
                                        child: Text(
                                          'RFID号:',
                                          // textAlign: TextAlign.end,
                                          style: TextStyle(
                                              color:
                                                  Utils.hexToColor('#999999'),
                                              fontSize: 14),
                                        ),
                                      ),
                                      Container(
                                        width: 460.w,
                                        height: 70.h,
                                        child: TextField(
                                          style: TextStyle(
                                              fontSize: 14,
                                              color: Utils.hexToColor(
                                                  '#297CFF')), //输入文本的样式
                                          decoration: InputDecoration(
                                            hintStyle: TextStyle(
                                                color: Color(0xFFC8C8D9),
                                                fontSize: 14),
                                            contentPadding: EdgeInsets.fromLTRB(
                                                21.w, 0, 21.w, 0),
                                            fillColor: Colors.white,
                                            filled: true,
                                            enabledBorder: OutlineInputBorder(
                                              borderRadius: BorderRadius.all(
                                                Radius.circular(8.w),
                                              ),
                                              borderSide: BorderSide(
                                                color:
                                                    Utils.hexToColor('#D4D4D4'),
                                                width: 1,
                                              ),
                                            ),
                                            focusedBorder: OutlineInputBorder(
                                              borderSide: BorderSide(
                                                color:
                                                    Utils.hexToColor('#D4D4D4'),
                                                width: 1,
                                              ),
                                              borderRadius: BorderRadius.all(
                                                Radius.circular(8.w),
                                              ),
                                            ),
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                  Container(
                                    margin: EdgeInsets.only(top: 17.w),
                                    child: Row(
                                      children: <Widget>[
                                        Text('*',
                                            style: TextStyle(
                                                color:
                                                    Utils.hexToColor('#F2332F'),
                                                fontSize: 12)),
                                        Text('温馨提示：请对准所需要绑定的物资进行扫描',
                                            style: TextStyle(
                                                color:
                                                    Utils.hexToColor('#999999'),
                                                fontSize: 12))
                                      ],
                                    ),
                                  ),
                                  Container(
                                    width: 580.w,
                                    height: 480.w,
                                    margin: EdgeInsets.only(top: 26.w),
                                    decoration: BoxDecoration(
                                        color: Utils.hexToColor('#F7FAFF'),
                                        borderRadius:
                                            BorderRadius.circular(12.w)),
                                    child: Column(
                                      children: <Widget>[
                                        Container(
                                          height: 90.w,
                                          padding: EdgeInsets.symmetric(
                                              horizontal: 31.w),
                                          decoration: BoxDecoration(
                                              border: Border(
                                                  bottom: BorderSide(
                                                      width: 1,
                                                      color: Utils.hexToColor(
                                                          '#EDEEF1')))),
                                          child: Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.spaceBetween,
                                            children: <Widget>[
                                              Text('01-02-03',
                                                  style: TextStyle(
                                                      color: Utils.hexToColor(
                                                          "#333333"),
                                                      fontSize: 14)),
                                              Container(
                                                child: RoundCheckBox(
                                                    select: false),
                                              )
                                            ],
                                          ),
                                        ),
                                      ],
                                    ),
                                  ),
                                  Container(
                                    margin: EdgeInsets.only(top: 20.w),
                                    child: Row(
                                      mainAxisAlignment:
                                          MainAxisAlignment.center,
                                      children: <Widget>[
                                        Image.asset('assets/error.png',
                                            width: 26.w),
                                        Text('扫描出多个RFID，请选择对应的RFID码',
                                            style: TextStyle(
                                                color:
                                                    Utils.hexToColor('#F54745'),
                                                fontSize: 12))
                                      ],
                                    ),
                                  )
                                ],
                              ),
                            ),
                          )),
                      Container(
                        height: 120.w,
                        alignment: Alignment.center,
                        margin: EdgeInsets.only(bottom: 24.w),
                        child: SizedBox(
                          width: 380.w,
                          height: 76.w,
                          child: ElevatedButton(
                            onPressed: () {
                              Navigator.of(context).pop();
                            },
                            child: Text(
                              '保存',
                              style: TextStyle(color: Colors.white),
                            ),
                            style: ElevatedButton.styleFrom(
                              backgroundColor: Color(0xFF297CFF),
                              shape: RoundedRectangleBorder(
                                  borderRadius:
                                      BorderRadius.all(Radius.circular(60.w))),
                            ),
                          ),
                        ),
                      ),
                    ],
                  )));
        });
  }

  Future<void> showSubmitDialog() async {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return Dialog(
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(Radius.circular(12.w))),
              insetPadding: EdgeInsets.all(0),
              child: Container(
                  width: 660.w,
                  height: 400.w,
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.all(Radius.circular(100))),
                  child: Column(
                    children: <Widget>[
                      Column(
                        children: <Widget>[
                          Container(
                            margin: EdgeInsets.only(top: 80.w),
                            child: Text('已提交给信息组',
                                style: TextStyle(
                                    color: Utils.hexToColor('#333333'),
                                    fontSize: 16,
                                    fontWeight: FontWeight.bold)),
                          ),
                          Container(
                              margin: EdgeInsets.only(top: 20.w),
                              child: Text('物资出库完成，查看进度请点击订单详情',
                                  style: TextStyle(
                                      color: Utils.hexToColor('#999999'),
                                      fontSize: 12))),
                        ],
                      ),
                      Container(
                        height: 120.w,
                        margin: EdgeInsets.only(top: 70.w),
                        alignment: Alignment.center,
                        child: SizedBox(
                          width: 380.w,
                          height: 76.w,
                          child: ElevatedButton(
                            onPressed: () {
                              Navigator.of(context).pop();
                            },
                            child: Text(
                              '我知道了',
                              style: TextStyle(color: Colors.white),
                            ),
                            style: ElevatedButton.styleFrom(
                              backgroundColor: Color(0xFF297CFF),
                              shape: RoundedRectangleBorder(
                                  borderRadius:
                                      BorderRadius.all(Radius.circular(60.w))),
                            ),
                          ),
                        ),
                      ),
                    ],
                  )));
        });
  }

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);

    return Scaffold(
        appBar: TopBar(
          title: "分拣出库",
          actions: <Widget>[
            InkWell(
              onTap: () {
                for (int i = 0; i < selected.length; i++) {
                  setState(() {
                    selected[i]['selected'] = !isSelectedAll;
                  });
                }
                setState(() {
                  isSelectedAll = !isSelectedAll;
                });
              },
              child: Container(
                alignment: Alignment.center,
                height: double.infinity,
                padding: EdgeInsets.symmetric(horizontal: 31.w),
                child: Text('全选'),
              ),
            )
          ],
        ),
        body: SafeArea(
          child: Container(
            child: Column(children: <Widget>[
              Container(
                height: 108.w,
                padding: EdgeInsets.all(24.w),
                color: Utils.hexToColor('#297CFF'),
                child: Row(children: <Widget>[
                  _buildButton('确认物资信息', '#409EFF', 1),
                  _buildButton('扫描RFID', '#FF9232', 2),
                ]),
              ),
              Expanded(
                flex: 1,
                child: Stack(
                  children: <Widget>[
                    _buildPageTwo(),
                    Align(
                      alignment: Alignment.bottomCenter,
                      child: Container(
                        width: 690.w,
                        height: 140.w,
                        margin: EdgeInsets.only(bottom: 30.w),
                        // color: Utils.hexToColor('#F5F6FA'),
                        child: Stack(
                          children: <Widget>[
                            Align(
                              alignment: Alignment.centerLeft,
                              child: Container(
                                // margin: EdgeInsets.only(top: 70.w),
                                child: SizedBox(
                                  width: 345.w,
                                  height: 106.w,
                                  child: ElevatedButton(
                                    onPressed: () {
                                      Utils.openAlert('确定要退回吗？', context)
                                          .then((confirm) => {
                                                if (confirm) {_back()}
                                              });
                                    },
                                    child: Row(
                                      mainAxisAlignment:
                                          MainAxisAlignment.center,
                                      children: <Widget>[
                                        Container(
                                            margin: EdgeInsets.only(left: 30.w),
                                            child: Image.asset(
                                                'assets/return.png',
                                                width: 28.w)),
                                        Container(
                                          margin: EdgeInsets.only(left: 16.w),
                                          child: Text(
                                            '退回',
                                            style:
                                                TextStyle(color: Colors.white),
                                          ),
                                        )
                                      ],
                                    ),
                                    style: ElevatedButton.styleFrom(
                                      backgroundColor: Color(0xFF297CFF),
                                      shape: RoundedRectangleBorder(
                                        borderRadius: BorderRadius.horizontal(
                                            left:
                                                Radius.elliptical(60.w, 60.w)),
                                      ),
                                    ),
                                  ),
                                ),
                              ),
                            ),
                            Align(
                              alignment: Alignment.centerRight,
                              child: Container(
                                // margin: EdgeInsets.only(top: 70.w),
                                child: SizedBox(
                                  width: 345.w,
                                  height: 106.w,
                                  child: ElevatedButton(
                                    onPressed: () {
                                      Utils.openAlert('确定要提交吗？', context)
                                          .then((confirm) => {
                                                if (confirm) {_out()}
                                              });
                                    },
                                    child: Row(
                                      mainAxisAlignment:
                                          MainAxisAlignment.center,
                                      children: <Widget>[
                                        Container(
                                            child: Image.asset(
                                                'assets/submit.png',
                                                width: 25.w)),
                                        Container(
                                          margin: EdgeInsets.only(left: 16.w),
                                          child: Text(
                                            '完成出库',
                                            style:
                                                TextStyle(color: Colors.white),
                                          ),
                                        )
                                      ],
                                    ),
                                    style: ElevatedButton.styleFrom(
                                      backgroundColor: Color(0xFF297CFF),
                                      shape: RoundedRectangleBorder(
                                        borderRadius: BorderRadius.horizontal(
                                            right:
                                                Radius.elliptical(60.w, 60.w)),
                                      ),
                                    ),
                                  ),
                                ),
                              ),
                            ),
                            Center(
                              child: Container(
                                width: 3.w,
                                height: 40.w,
                                color: Utils.hexToColor('#7EB1FF'),
                              ),
                            )
                          ],
                        ),
                      ),
                    )
                  ],
                ),
              ),
            ]),
          ),
        ));
  }
}
